package com.jk.controller;

import com.jk.po.OrderPO;
import com.jk.service.HotelService;
import com.jk.service.PayService;
import com.jk.utils.ReturnMsgUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.Map;

@Controller
@RequestMapping("Pay")
public class PayController {

    @Autowired
    private PayService payService;



    /**
     * @param id
     * @author 段卓帆
     * @date 2021/7/8 15:20
     * @return
     */
    //付完款之后修改订单状态为已支付
    @RequestMapping("upStatusById")
    public void upStatusById(String id){
        payService.upStatusById(id);
    }



    //付费接口
    @RequestMapping("payMoney")
    public Map payMoney(Integer totalprice){
        //获取共享session
        ServletRequestAttributes requestAttributes = ( ServletRequestAttributes ) RequestContextHolder.getRequestAttributes();
        HttpSession session = requestAttributes.getRequest().getSession();
        //然后通过
        OrderPO us = (OrderPO)session.getAttribute("order");
        if(us == null){
            return ReturnMsgUtils.returnMsg(300,"用户未登录",null);
        }else if(totalprice == null){
            return ReturnMsgUtils.returnMsg(301,"请输入扣款金额",null);
        }else{
            BigDecimal bb = BigDecimal.valueOf(totalprice);
            return payService.payMoney(us.getId(), totalprice);

        }
    }
}
